<?php 
	namespace Home\Model;
	use Think\Model;
	class OrderListModel extends Model{
		//自动完成
		protected $_auto=array(
			array('ordertime','time',1,'function')
			);
		//添加
		public function getAdd($data)
		{//向订单表中插入，返回最后插入ID
			$res=$this->data($data)->add();
			//echo $res;exit;
			return $res;
		}
		//查询订单详情
		public function getAll($uid,$limit)
		{
			$sql="select * from `order_list` where `uid`=$uid order by ordertime desc limit $limit";
			$list=$this->query($sql);
			//var_dump($list);exit;
			if (!empty($list)) 
			{
				foreach ($list as $k => $v) 
				{
					$info_list=$this->field('
								g.id      		gid,
								g.price  		gp,
								gi.name   		giname,
								g.description   gd,
								oi.num 			ion')
							->table('goods        g,
									goods_img	  gi,
									order_list	  ol,
									order_info	  oi')
							->where("g.id=oi.goods_id
								and
									g.id=gi.goods_id
								and
									ol.id=oi.order_id
								and
							   	 	gi.is_cover=1
								and
									ol.id=".$v['id'])
					->limit(0,2)
					->select();
					//var_dump($info_list);exit;
				$list[$k]['son']=$info_list;
				}
				//var_dump($list[$k]['son']);exit;
			}
			//var_dump($list);exit;
			return $list;
		}


	}

?>